<?php
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['title']){
		$params['nickname like']='%'.trim($_RQ['nickname']).'%';
		$return['params']['nickname']=$_RQ['nickname'];
	}
	if($_RQ['uid']){
		$params['uid']=$_RQ['uid'];
		$return['params']['uid']=$_RQ['uid'];
	}
	$orderby=array();
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_jdk_members',$params,array($pindex,$psize),$total,$fields,'','id desc');
	foreach($list as &$v){
		$v['createtime']=date('Y-m-d H:i:s',$v['createtime']);
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'会员列表'),
			
		),
		'list'=>array('data'=>'list','edit'=>true,'list'=>array(
			array('name'=>'uid','title'=>'会员ID','type'=>'string'),
			array('name'=>'avatar','title'=>'头像','type'=>'image'),
			array('name'=>'nickname','title'=>'会员昵称','type'=>'string'),
			//array('name'=>'type','title'=>'类型','type'=>'radio','options'=>'type'),
			array('name'=>'credit1','title'=>'积分','type'=>'string'),
			array('name'=>'credit2','title'=>'余额','type'=>'string'),
			array('name'=>'createtime','title'=>'注册时间','type'=>'string'),
			
		)),
		'search_one'=>array('name'=>'nickname','help'=>'昵称','add'=>false),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_jdk_members',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'会员',
		'tabs'=>array(
			array('op'=>'list','title'=>'会员列表'),
			
		),
		'edit'=>array(
			array('name'=>'uid','title'=>'会员ID','type'=>'string'),
			array('name'=>'avatar','title'=>'头像','type'=>'image'),
			array('name'=>'nickname','title'=>'会员昵称','type'=>'string'),
		//	array('name'=>'type','title'=>'类型','type'=>'radio','options'=>'type'),
			array('name'=>'credit1','title'=>'积分','type'=>'string'),
			array('name'=>'credit2','title'=>'余额','type'=>'string'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_jdk_members',$postdata,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		exi('修改成功！');
	}else{
		$postdata['uniacid']=$_SESSION['uniacid'];
		
		pdo_update('jy_jdk_members',$postdata,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		exi('保存成功！');
	}
}

if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_jdk_members',array('id'=>$id));
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_jdk_members',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
